import md5 from 'md5-js';
import sha1 from 'js-sha1';
import {sha224, sha256} from 'js-sha256';

export default class Checksum {
  static Name = "<%= UIText.Checksum %>";

  static Options = {
    method: {
      type: 'menu',
      options: ['MD5', 'SHA-1', 'SHA-224', 'SHA-256']
    },
    uppercase: {
      type: 'switch',
      label: 'Upper Case',
    },
  }

  options = {
    method: 'MD5',
    uppercase: false,
  }

  compute(data) {
    let code = () => {
      switch(this.options.method) {
        case 'MD5':
          return md5(data);
        case 'SHA-1':
          return sha1(data);
        case 'SHA-224':
          return sha224(data);
        case 'SHA-256':
          return sha256(data);
      }
    };
    if (this.options.uppercase) {
      return code().toUpperCase();
    } else {
      return code();
    }
  }
}
